package com.nativetalk.service.authentication.search;

import com.nativetalk.base.RetInfo;
import com.nativetalk.bean.authentication.TdNtAuthenticationDetail;
import com.nativetalk.common.ValidationMessages;
import com.nativetalk.common.util.I18nMessages;
import com.nativetalk.dao.TdNtAuthenticationDao;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by lizhun on 16/1/13.
 */
@Service
public class AuthenticationSearchServiceImpl implements  AuthenticationSearchService {
    private static Logger logger = Logger.getLogger(AuthenticationSearchServiceImpl.class);
    @Resource
    private TdNtAuthenticationDao tdNtAuthenticationDao;
    @Override
    public RetInfo findAuthentication(int tea_id) {
        String logInfo = this.getClass().getName() + ":findAuthentication:";
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            TdNtAuthenticationDetail tdNtAuthenticationDetail = tdNtAuthenticationDao.findTdNtAuthentication(tea_id);
            /**
             * 判断有没有认证记录
             */
            if (tdNtAuthenticationDetail != null) {
                switch (tdNtAuthenticationDetail.getAuh_state()) {
                    /**
                     * 审核中
                     */
                    case "1":
                        retInfo.setMark("701");
                        retInfo.setTip(I18nMessages.en.getString("verify.verifying"));
                        break;
                    /**
                     * 审核成功
                     */
                    case "2":
                        retInfo.setMark(ValidationMessages.getValue("MARKYES"));
                        retInfo.setTip(I18nMessages.en.getString("verify.success"));
                        Map<String,Object> map = new HashMap<>();
                        map.put("payPal",tdNtAuthenticationDetail.getPayPal());
                        map.put("tea_head_portrait",tdNtAuthenticationDetail.getTea_head_portrait());
                        map.put("student_id",tdNtAuthenticationDetail.getStudent_id());
                        map.put("tea_sound_synopsis",tdNtAuthenticationDetail.getTea_sound_synopsis());
                        retInfo.setObj(map);
                        break;
                    /**
                     * 审核失败
                     */
                    case "3":
                        retInfo.setMark("702");
                        retInfo.setTip(I18nMessages.en.getString("verify.fail"));
                        retInfo.setObj(tdNtAuthenticationDetail.getAuh_expalin());
                        break;

                }
            } else {
                retInfo.setMark("700");
                retInfo.setTip(I18nMessages.en.getString("verify.warning"));
            }
        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(),e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }
}
